package utils;

import java.util.*;
import utils.*;

public class NBayes {
	static int sum;
	//get one directory total words number
	public static int totalWords(HashMap<String,HashMap<String,Integer>> selected){
		sum=0;
		for(String file:selected.keySet()){
			HashMap<String,Integer> dict=new HashMap<String,Integer>();
			dict=selected.get(file);
			for(String word:dict.keySet()){
				sum=sum+dict.get(word);
			}
		}
		return sum;
	}
	
	//
	public static HashMap<String,Integer> wordNum(HashMap<String,HashMap<String,Integer>> selected){
		HashMap<String,Integer> cmap=new HashMap<String,Integer>();
		for(String file:selected.keySet()){
			HashMap<String,Integer> dict=new HashMap<String,Integer>();
			dict=selected.get(file);
			for(String word:dict.keySet()){
				if(cmap.containsKey(word)){
					cmap.put(word, cmap.get(word)+dict.get(word));
					int temp1=cmap.get(word);
					int temp2=dict.get(word);
				}else{
					cmap.put(word, dict.get(word));
				}
			}
		}
		return cmap;
	}
	
	//
	public static HashMap<String ,Float> wordPr(HashMap<String,Integer> cmap){
		HashMap<String,Float> cprMap=new HashMap<String,Float>();
		for(String word:cmap.keySet()){
			Float wpr=(float)Float.parseFloat(cmap.get(word).toString())/sum;
			cprMap.put(word, wpr);
		}
		return cprMap;
	}
	
//***************//	
}
